package com.example.book.common.configs;

import com.example.book.common.utils.Constants;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.web.servlet.MultipartConfigFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.util.unit.DataSize;

import javax.servlet.MultipartConfigElement;
import java.io.File;

/**
 * 系统相关配置 文件上传配置
 * @author haocjia
 */
@Configuration
public class SystemConfig {

    @Value("${system.profile.real_path}")
    private String realProfile;

    /**
     * 文件上传大小配置
     * @return
     */
    @Bean
    public MultipartConfigElement multipartConfigElement() {
        //创建文件路径
        File file = new File(realProfile);
        if (!file.exists()) {
            file.mkdir();
        }
        MultipartConfigFactory factory = new MultipartConfigFactory();
        factory.setMaxFileSize(DataSize.parse("10240KB"));
        factory.setMaxRequestSize(DataSize.parse("102400KB"));
        return factory.createMultipartConfig();

    }

}
